package io.github.yotta.dict.autoconfiguration;

import io.github.yotta.dict.api.service.SysDictService;
import io.github.yotta.dict.dao.entity.SysDictDao;
import io.github.yotta.dict.server.converter.SysDictConverter;
import io.github.yotta.dict.server.service.impl.SysDictServiceImpl;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConditionalOnClass(SysDictServiceImpl.class)
@ConditionalOnBean(SysDictDao.class)
public class SysDictServiceAutoConfiguration {

    @Bean
    @ConditionalOnMissingBean(SysDictConverter.class)
    public SysDictConverter sysDictConverter() {
        return SysDictConverter.INSTANCE;
    }

    @Bean
    @ConditionalOnMissingBean(SysDictService.class)
    public SysDictService sysDictService(SysDictDao sysDictDao,
                                         SysDictConverter sysDictConverter) {
        SysDictServiceImpl sysDictService = new SysDictServiceImpl();
        sysDictService.setSysDictConverter(sysDictConverter);
        sysDictService.setSysDictDao(sysDictDao);
        return sysDictService;
    }

}